import { LOGIN_SUCCESS } from"../actions/action-types"
import {getWebStorage} from '../utils/index'
import {genAsyncRoutes} from '../utils/permission'
const initState = getWebStorage('user')||{
  username:'',
  nickname:'',
  avatar: '',
  token:'',
  roles:[],
  routes:[]
}
if(!initState.routes||initState.routes.length===0){
  const routes =genAsyncRoutes(initState.roles)
  initState.routes =routes
}
const reducer = (state=initState,{type,payload})=>{
  switch(type){
    case LOGIN_SUCCESS:
      return {
        ...state,...payload
      }
    default:
      return state
  }

}
export default reducer